home *** CD-ROM | disk | FTP | other *** search
- 10 ! *******************************************************************
- 20 ! Example: Dialogs Tests
- 30 !
- 40 ! This program tests HP BASIC for Windows dialogs.
- 50 !
- 60 ! *******************************************************************
- 70 !
- 80 ! Seed random-number generator with current time (manipulating to
- 90 ! produce a seed that varies rapidly over a wide range, ensuring
- 100 ! diversity in random-number sequences):
- 110 !
- 120 CLEAR SCREEN
- 130 RANDOMIZE INT(FRACT(TIMEDATE)*10^7)
- 140 OPTION BASE 0
- 150 !
- 160 ! Variables to store PEN colors:
- 170 !
- 180 INTEGER Black,White,Red,Yellow,Green,Cyan,Blue,Magenta
- 190 DATA 0,1,2,3,4,5,6,7
- 200 READ Black,White,Red,Yellow,Green,Cyan,Blue,Magenta
- 210 !
- 220 ! Some other variables:
- 230 !
- 240 ! S$: String variable
- 250 ! P$: Stores a prompt
- 260 ! D$: Returns directory from FILE dialog
- 270 ! F$: Returns file from FILE dialog
- 280 ! N: INTEGER variable
- 290 ! X: REAL vaiable
- 300 ! Btn: Variable to get button inputs from dialogs
- 310 ! D(*): Array to get display dimensions for BASIC
- 320 !
- 330 DIM S$[256],P$[100],M$(0:6)[50]
- 340 INTEGER N,Btn,D(1:4)
- 350 REAL X
- 360 !
- 370 DATA "COSMOPOLITAN","ENQUIRER","DISCOVER","TIME","HEALTH"
- 380 DATA "SPORTS ILLUSTRATED","NEW YORKER"
- 390 READ M$(*)
- 400 !
- 410 ! Variables to store widget & display coordinates and dimensions:
- 420 !
- 430 INTEGER Px,Py,Pw,Ph! Main PANEL
- 440 INTEGER Iw,Ih ! Inside dimensions of main PANEL
- 450 INTEGER Dw,Dh ! Display dimensions
- 460 !
- 470 ! Get display size
- 480 !
- 490 GESCAPE CRT,3;D(*)
- 500 Dw=D(3)-D(1)
- 510 Dh=D(4)-D(2)
- 520 !
- 530 CLEAR SCREEN
- 540 !
- 550 ! Set default coordinates for main PANEL
- 560 !
- 570 Pw=Dw*.75
- 580 Ph=Dh*.75
- 590 Px=(Dw-Pw)/2
- 600 Py=(Dh-Ph)/2
- 610 !
- 620 ! Create the PANEL widget
- 630 !
- 640 ASSIGN @Main TO WIDGET "PANEL";SET ("VISIBLE":0)
- 650 CONTROL @Main;SET ("X":Px,"Y":Py,"WIDTH":Pw,"HEIGHT":Ph)
- 660 CONTROL @Main;SET ("MAXIMIZABLE":0,"RESIZABLE":0)
- 670 CONTROL @Main;SET ("TITLE":" Example: Dialogs")
- 680 !
- 690 ! Set up menu
- 700 !
- 710 S$="Dialog Tests"
- 720 ASSIGN @Menu TO WIDGET "PULLDOWN MENU";PARENT @Main,SET ("LABEL":S$)
- 730 !
- 740 S$="ERROR"
- 750 ASSIGN @Errtest TO WIDGET "MENU BUTTON";PARENT @Menu,SET ("LABEL":S$)
- 760 !
- 770 S$="INFORMATION"
- 780 ASSIGN @Infotest TO WIDGET "MENU BUTTON";PARENT @Menu,SET ("LABEL":S$)
- 790 !
- 800 S$="QUESTION"
- 810 ASSIGN @Qtest TO WIDGET "MENU BUTTON";PARENT @Menu,SET ("LABEL":S$)
- 820 !
- 830 S$="WARNING"
- 840 ASSIGN @Warntest TO WIDGET "MENU BUTTON";PARENT @Menu,SET ("LABEL":S$)
- 850 !
- 860 ASSIGN @S1 TO WIDGET "MENU SEPARATOR";PARENT @Menu
- 870 !
- 880 S$="STRING"
- 890 ASSIGN @Stringtest TO WIDGET "MENU BUTTON";PARENT @Menu,SET ("LABEL":S$)
- 900 !
- 910 S$="NUMBER"
- 920 ASSIGN @Numtest TO WIDGET "MENU BUTTON";PARENT @Menu,SET ("LABEL":S$)
- 930 !
- 940 S$="KEYPAD"
- 950 ASSIGN @Keytest TO WIDGET "MENU BUTTON";PARENT @Menu,SET ("LABEL":S$)
- 960 !
- 970 ASSIGN @S2 TO WIDGET "MENU SEPARATOR";PARENT @Menu
- 980 !
- 990 S$="LIST"
- 1000 ASSIGN @Listtest TO WIDGET "MENU BUTTON";PARENT @Menu,SET ("LABEL":S$)
- 1010 !
- 1020 S$="COMBO"
- 1030 ASSIGN @Combotest TO WIDGET "MENU BUTTON";PARENT @Menu,SET ("LABEL":S$)
- 1040 !
- 1050 ASSIGN @S3 TO WIDGET "MENU SEPARATOR";PARENT @Menu
- 1060 !
- 1070 S$="FILE"
- 1080 ASSIGN @Filetest TO WIDGET "MENU BUTTON";PARENT @Menu,SET ("LABEL":S$)
- 1090 !
- 1100 ASSIGN @S4 TO WIDGET "MENU SEPARATOR";PARENT @Menu
- 1110 !
- 1120 S$="Quit"
- 1130 ASSIGN @Quit TO WIDGET "MENU BUTTON";PARENT @Menu,SET ("LABEL":S$)
- 1140 !
- 1150 ! Build PRINTER widget
- 1160 !
- 1170 COM @Prn
- 1180 ASSIGN @Prn TO WIDGET "PRINTER";PARENT @Main
- 1190 STATUS @Main;RETURN ("INSIDE WIDTH":Iw,"INSIDE HEIGHT":Ih)
- 1200 CONTROL @Prn;SET ("X":0,"Y":0,"WIDTH":Iw,"HEIGHT":Ih)
- 1210 CONTROL @Prn;SET ("BACKGROUND":Blue,"PEN":White)
- 1220 !
- 1230 ! Set up events for menu entries and PANEL resize, then loop.
- 1240 !
- 1250 ON EVENT @Errtest,"ACTIVATED" GOSUB Errtest
- 1260 ON EVENT @Infotest,"ACTIVATED" GOSUB Infotest
- 1270 ON EVENT @Qtest,"ACTIVATED" GOSUB Qtest
- 1280 ON EVENT @Warntest,"ACTIVATED" GOSUB Warntest
- 1290 ON EVENT @Stringtest,"ACTIVATED" GOSUB Stringtest
- 1300 ON EVENT @Numtest,"ACTIVATED" GOSUB Numtest
- 1310 ON EVENT @Keytest,"ACTIVATED" GOSUB Keytest
- 1320 ON EVENT @Listtest,"ACTIVATED" GOSUB Listtest
- 1330 ON EVENT @Combotest,"ACTIVATED" GOSUB Combotest
- 1340 ON EVENT @Filetest,"ACTIVATED" GOSUB Filetest
- 1350 !
- 1360 ON EVENT @Quit,"ACTIVATED" GOTO Finis
- 1370 !
- 1380 CONTROL @Main;SET ("VISIBLE":1)
- 1390 CALL Printit("Click Dialog Tests to select a test from the menu.")
- 1400 !
- 1410 LOOP
- 1420 WAIT FOR EVENT
- 1430 END LOOP
- 1440 !
- 1450 ! ******************* End of Main Program **************************
- 1460 !
- 1470 Errtest:!
- 1480 P$="Input caused overflow"
- 1490 DIALOG "ERROR",P$;SET ("TITLE":" Example: ERROR Dialog")
- 1500 RETURN
- 1510 !
- 1520 Infotest:!
- 1530 P$="Here is the information required"
- 1540 DIALOG "INFORMATION",P$;SET ("TITLE":" Example: INFORMATION Dialog")
- 1550 RETURN
- 1560 !
- 1570 Qtest:!
- 1580 P$="Do you want to exit?"
- 1590 DIALOG "QUESTION",P$,Btn;SET ("TITLE":" Example: QUESTION Dialog")
- 1600 SELECT Btn
- 1610 CASE 0
- 1620 CALL Printit("QUESTION Dialog: Btn = 0: YES")
- 1630 CASE 1
- 1640 CALL Printit("QUESTION Dialog: Btn = 1: NO")
- 1650 END SELECT
- 1660 RETURN
- 1670 !
- 1680 Warntest:!
- 1690 P$="Core meltdown in one minute!!"
- 1700 DIALOG "WARNING",P$;SET ("TITLE":" Example: WARNING Dialog")
- 1710 RETURN
- 1720 !
- 1730 Stringtest:!
- 1740 P$=" Please enter your name:"
- 1750 DIALOG "STRING",P$,Btn;SET ("TITLE":" Example: STRING Dialog"),RETURN ("VALUE":S$)
- 1760 SELECT Btn
- 1770 CASE 0
- 1780 CALL Printit("STRING Dialog: "&S$)
- 1790 CASE 1
- 1800 CALL Printit("STRING Dialog: No string input")
- 1810 END SELECT
- 1820 RETURN
- 1830 !
- 1840 Numtest:!
- 1850 P$="Please input a number:"
- 1860 DIALOG "NUMBER",P$,Btn;SET ("TITLE":" Example: NUMBER Dialog"),RETURN ("VALUE":X)
- 1870 SELECT Btn
- 1880 CASE 0
- 1890 CALL Printit("NUMBER Dialog: "&VAL$(X))
- 1900 CASE 1
- 1910 CALL Printit("NUMBER Dialog: No number input")
- 1920 END SELECT
- 1930 RETURN
- 1940 !
- 1950 Keytest:!
- 1960 P$="Please input a number:"
- 1970 DIALOG "KEYPAD",P$,Btn;SET ("TITLE":" Example: KEYPAD Dialog"),RETURN ("VALUE":X)
- 1980 SELECT Btn
- 1990 CASE 0
- 2000 CALL Printit("KEYPAD Dialog: "&VAL$(X))
- 2010 CASE 1
- 2020 CALL Printit("KEYPAD Dialog: No number input")
- 2030 END SELECT
- 2040 RETURN
- 2050 !
- 2060 Listtest:!
- 2070 P$="What is your favorite magazine?"
- 2080 DIALOG "LIST",P$,Btn;SET ("TITLE":" Example: LIST Dialog","ITEMS":M$(*)),RETURN ("SELECTION":N)
- 2090 IF Btn=0 AND N=-1 THEN CALL Printit("LIST Dialog: No selection from list")
- 2100 IF Btn=0 AND N<>-1 THEN CALL Printit("LIST Dialog: "&M$(N))
- 2110 RETURN
- 2120 !
- 2130 Combotest:!
- 2140 P$="What is your favorite magazine?"
- 2150 DIALOG "COMBO",P$,Btn;SET ("TITLE":" Example: COMBO Dialog","ITEMS":M$(*)),RETURN ("TEXT":S$)
- 2160 IF Btn=0 AND S$="" THEN CALL Printit("COMBO Dialog: No selection from list")
- 2170 IF Btn=0 AND S$<>"" THEN CALL Printit("COMBO Dialog: "&S$)
- 2180 RETURN
- 2190 !
- 2200 Filetest:!
- 2210 P$="Please select a file:"
- 2220 DIALOG "FILE",P$,Btn;SET ("TITLE":" Example: FILE Dialog"),RETURN ("SELECTION":S$)
- 2230 SELECT Btn
- 2240 CASE 0
- 2250 CALL Printit("FILE Dialog: "&S$)
- 2260 CASE 1
- 2270 CALL Printit("FILE Dialog: No file input")
- 2280 END SELECT
- 2290 RETURN
- 2300 !
- 2310 Finis:!
- 2320 ASSIGN @Main TO *! Delete main panel
- 2330 END
- 2340 !
- 2350 ! Subprogram to print text to PRINTER widget
- 2360 !
- 2370 SUB Printit(S$)
- 2380 COM @Prn
- 2390 CONTROL @Prn;SET ("APPEND TEXT":S$)
- 2400 SUBEND
-